package com.cm.controller;

import com.cm.pojo.Dept;
import com.cm.pojo.Result;
import com.cm.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * ClassName:  DeptController
 * Package: com.cm.controller
 * Description:
 *
 * @Author:
 * @Create: 2025/7/12  2:40
 * @Version 1.0
 */
@Slf4j
@RestController
@RequestMapping("/depts")
public class DeptController {
    //写了slf4j就不用写下面的这些了
//    private static final Logger log= LoggerFactory.getLogger(DeptController.class);
    @Autowired
    private DeptService deptService;
  @GetMapping
    public Result list(){
        deptService.findall();
        log.info("查询全部数据");
      System.out.println(123);
        return Result.success(deptService.findall());
    }
    @DeleteMapping
    public Result delete(Integer id){
        deptService.delete(id);
        log.info("删除部门{}",id);
        return Result.success();
    }
    @PostMapping
    public Result add(@RequestBody Dept dept){

        deptService.add(dept);
        log.info("添加部门{}",dept);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result searchById(@PathVariable Integer id) {
        deptService.searchById(id);
        log.info("根据id进行部门查询{}",id);
        return Result.success(deptService.searchById(id) );
    }
    @PutMapping
        public Result update(@RequestBody Dept dept){
        deptService.update(dept);
        log.info("更新部门{}",dept);
        return Result.success();
    }

}
